interface Rules {
    phone: RegExp,
    HKPhone:RegExp,
    DaLuPhone:RegExp
}

const rules: Rules = {
    phone: /(^1[3|4|5|7|8]\d{9}$)|(^(852)?([5|6|9])\d{7}$)|(^(853)?[6|8]\d{7}$)/,
    HKPhone:/(^(852)?([5|6|9])\d{7}$)|(^(853)?[6|8]\d{7}$)/,
    DaLuPhone:/(^1[3|4|5|7|8]\d{9}$)/
}


/**
 * @description:  检查验证规则
 * @param {string} key
 * @return {*}
 */
export default function validateRule(str: string, key: keyof Rules): boolean {
    if (!rules[key]) {
        console.error("没有找到该规则");
        return false;
    }
    return rules[key].test(str);
}

/**
 * @description:  获取校验规则
 * @param {string} key
 * @return {*}
 */
export const getValidateRule = (key: keyof Rules): RegExp => {
    return rules[key];
}
